//
//  OpenZuopinCell.m
//  jingdongfang
//
//  Created by MTiMac02 on 2017/9/6.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "OpenZuopinCell.h"
#import "IGDatabaseApi.h"
@interface OpenZuopinCell () {
    UIImageView *imgView;
    UIImageView *selImag;
    UIImageView *shadowImag;
    UILabel *messageLabel;
    NSInteger type;
}

@end
@implementation OpenZuopinCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self _initView];
    }
    return self;
}

- (void)_initView {
    imgView = [[UIImageView alloc] initWithFrame:CGRectZero];
    imgView.contentMode = UIViewContentModeScaleAspectFill;
    imgView.clipsToBounds = YES;
    
    shadowImag=[[UIImageView alloc]initWithFrame:CGRectZero];
    shadowImag.backgroundColor=[UIColor blackColor];
    shadowImag.alpha=0.7;
    
    messageLabel=[[UILabel alloc]initWithFrame:CGRectZero];
    messageLabel.font=[UIFont  systemFontOfSize:14 weight:14];
    messageLabel.textColor=[UIColor whiteColor];
    [messageLabel sizeToFit];
    messageLabel.textAlignment=NSTextAlignmentCenter;
    [shadowImag addSubview:messageLabel];
    shadowImag.hidden=YES;
    
    [imgView addSubview:shadowImag];
    
    [self.contentView addSubview:imgView];
    
    selImag = [[UIImageView alloc] initWithFrame:CGRectZero];
    selImag.contentMode = UIViewContentModeScaleAspectFit;
    selImag.hidden = YES;
    [self.contentView addSubview:selImag];
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];

    IGArtWorkModel *list = self.data;
    
    imgView.frame = CGRectMake(0, 0, self.width, self.height);
    shadowImag.frame=CGRectMake(0, 0, self.width, 35);
    shadowImag.bottom=imgView.bottom;
    
//    messageLabel.text=@"待认证";
    messageLabel.text=NSLocalizedString(@"To be Verified", nil);
    messageLabel.frame = CGRectMake(0, 0, imgView.width-20, 35);
    messageLabel.centerX=shadowImag.centerX;

    //图片加载动画
    [imgView sd_setImageWithURL:[NSURL URLWithString:list.image] placeholderImage:[UIImage imageNamed:@"new"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (image) {
            // Image load from disk or download from network.
            if (cacheType == SDImageCacheTypeNone || cacheType == SDImageCacheTypeDisk) {
                imgView.alpha = 0.2;
                [UIView transitionWithView:imgView
                                  duration:2.0
                                   options:UIViewAnimationOptionCurveEaseInOut
                                animations:^{
                                    [imgView setImage:image];
                                    imgView.alpha = 1.0;
                                } completion:NULL];
            } else {
                imgView.alpha = 1.f;
            }
        }
    }];
    //判断作品状态
    if ([list.examine integerValue]==1||[list.examine integerValue]==3) {
        shadowImag.hidden=YES;
    }else{
         shadowImag.hidden=NO;
        if ([list.examine integerValue]==2) {
//            messageLabel.text=@"审核中";
            messageLabel.text=NSLocalizedString(@"Under Verification", nil);
        }else if([list.examine integerValue]==4){
//            messageLabel.text=@"审核未通过";
            messageLabel.text = NSLocalizedString(@"Examination Failed", nil);
        }
    }
//判断作品是否被选择
    if (self.isEdit)
    {
        selImag.hidden = NO;
        selImag.frame = CGRectMake(0, 0, 40, 40);
        selImag.right = self.width;
        if (self.isSel)
        {
            selImag.image = [UIImage imageNamed:@"切图 QH 20160704-12"];
        } else
        {
            selImag.image = [UIImage imageNamed:@"切图 QH 20160704-13"];
        }
    } else {
        selImag.hidden = YES;
    }
    
}
- (void)awakeFromNib
{
    [super awakeFromNib];
}

@end
